package com.tbit.api;

import cn.hutool.core.bean.BeanUtil;
import com.tbit.common.entity.view.Result;
import com.tbit.manager.api.UserCardApi;
import com.tbit.uqbike.object.pojo.vo.EfficientCardVO;
import com.tbit.uqbike.service.business.RideLogDetailsService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 人工结束订单使用卡券
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2025-4-1
 */
@RestController
public class UserCardServiceImpl implements UserCardApi {


    @Resource
    private RideLogDetailsService rideLogDetailsService;


    /**
     * 获取用户有效卡券卡券
     * @param userId    用户id
     * @param accountId 区域id
     * @return  Map<String, Object>
     */
    @Override
    public Map<String, Object> getEfficientCard(Integer userId, Integer accountId) {
        if (Objects.isNull(userId) || Objects.isNull(accountId)){
            return new HashMap<>();
        }
        return BeanUtil.beanToMap(rideLogDetailsService.getEfficientCard(userId, accountId).getData());
    }


    /**
     * 消费卡券
     * @param userId        用户id
     * @param accountId     区域id
     * @param rideCardId    骑行卡id
     * @param vipId         会员卡id
     * @param couponId      优惠券id
     * @return Map<String, Object>
     */
    @Override
    public Map<String, Object> consumptionCardCoupon(Integer userId, Integer accountId, Integer rideCardId, Integer vipId, Integer couponId) {
        Map<String, Object> map = new HashMap<>();
        if (Objects.isNull(userId) || Objects.isNull(accountId)){
            return map;
        }
        if (Objects.nonNull(rideCardId) || Objects.nonNull(vipId) || Objects.nonNull(couponId)) {
            String s = rideLogDetailsService.consumptionCardCoupon(userId, accountId, rideCardId, vipId, couponId);
            map.put("remark", s);
        }
        return map;
    }
}
